package com.jinbei.mq;

import org.apache.activemq.command.ActiveMQTopic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Topic;

/**
 * @author zflu
 * active mq 发布
 * Created by lucky on 2018/8/7.
 */
@Component
public class ActiveMqPublish {

    private final Logger logger = LoggerFactory.getLogger(ActiveMqPublish.class);

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Value("${activemq.topic}")
    private String topics;

    /**
     * @author zflu
     * @Description   发送消息
     * @date 2018/8/7 17:04
     * @param message
     * @return void
     */
    public void publish(String message){
        Topic topic = new ActiveMQTopic(topics);
        try {
            jmsMessagingTemplate.convertAndSend(topic,message);
        }catch (Exception e){
            logger.error("JSM 活动课程 发送失败! error:",e.getMessage());
        }
    }
}
